package Commnads;
import java.util.ArrayList;
import java.util.concurrent.Executor;

import Listening.Listener;

/**
 * From this class we execute the commands that had initiated by the {@link Listener}.
 *  we call to the command from class {@link Commands}, that contain all the commands.
 *  each command had been executed in each thread by the {@link Executor}
 * @author DROR
 */

public class ListenCommands 
{
	private Commands commands;
	
	/**
	 * Constructor
	 * @param com reference of {@link Commands} class
	 */
	public ListenCommands(Commands com) 
	{
		commands= com;
	}
	
	/**
	 * This function tagging automatically a file 
	 * @param file The path of the file by {@link String}
	 */
	public void autoTag(String file)
	{
		Commands.autoTaggingCommand c = (Commands.autoTaggingCommand)commands.getCom("auto tag");
		c.setPathOnString(file);
		c.execute();
	}
	
	/**
	 * This function remove directory from listening
	 * @param dir the path of directory by {@link String}
	 */
	public void removeDir(String dir)
	{
		Commands.removeDir c = (Commands.removeDir)commands.getCom("remove dir");
		c.setPathOnString(dir);
		c.execute();
	}
	
	/**
	 * This function returns all the regular expressions from DB 
	 * @return an {@link ArrayList} of all the regular expressions from DB 
	 */
	public ArrayList<String> getAllExpressions()
	{
		Commands.getAllExpressionsCommand c = (Commands.getAllExpressionsCommand)commands.getCom("get expressions");
		c.execute();
		return c.getExpressions();
	}
	
	/**
	 * This function returns all listened directories from DB
	 * @return an {@link ArrayList} of all listened directories from DB
	 */
	public ArrayList<String> getDirectories()
	{
		Commands.getDirectoriesCommand c = (Commands.getDirectoriesCommand)commands.getCom("get directories");
		c.execute();
		return c.getDirs();
	}
	
	/**
	 * This function remove file from listening (and from DB)
	 * @param file the path of the file by {@link String}
	 */
	public void removeFile(String file)
	{
		Commands.removeFileCommand c = (Commands.removeFileCommand)commands.getCom("remove file");
		c.setPathOnString(file);
		c.execute();
	}
	
	/**
	 * This function remove all tags of selected file ( removes from DB)
	 * @param path the path of the file by {@link String}
	 */
	public void removeTagsFromFile(String path)
	{
		Commands.removeTagsFromFileCommand c = (Commands.removeTagsFromFileCommand)commands.getCom("remove tags from file");
		c.setPathOnString(path);
		c.execute();

	}
	
	/**
	 * This function updates the Log about new operation
	 * @param oper The operation by {@link String} that had been recognized
	 */
	public void insertToLog(String oper)
	{
		Commands.insertToLogCommand c = (Commands.insertToLogCommand)commands.getCom("insert to log");
		c.setOperation(oper);
		c.execute();
	}
}

